﻿using AutoMapper;
using BW.MesProject.BasicData.Domain.基础;
using BW.MesProject.BasicData.Infrastructure;
using BW.MesProject.Public.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BW.MesProject.BasicData.Host.Controllers
{

    /// <summary>
    /// 物料组
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialgroupController : ControllerBase
    {
        private readonly IMaterialgroupServices materialgroupServices;

        public MaterialgroupController(IMaterialgroupServices materialgroupServices)
        {
            this.materialgroupServices = materialgroupServices;
        }
        /// <summary>
        /// 新增物料组
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> AddMaterialgroup(Materialgroupmodel model)
        {
            return materialgroupServices.AddMaterialgroup(model);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> DeleteMaterialgroup(long id)
        {
            return materialgroupServices.DeleteMaterialgroup(id);
        }
        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<List<Materialgroupmodel>> GetAllMaterialgroup()
        {
            return materialgroupServices.GetAllMaterialgroup();
        }
        /// <summary>
        /// 获取所有物料组
        /// </summary>
        /// <param name="Materialgroupcode"></param>
        /// <param name="Materialgroupname"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiPaging<List<Materialgroupmodel>> GetMaterialgroup(string? Materialgroupcode, string? Materialgroupname,string? Materialgrouptype, int pageindex, int pagesize)
        {
            return materialgroupServices.GetMaterialgroup(Materialgroupcode, Materialgroupname, Materialgrouptype, pageindex, pagesize);
        }
        /// <summary>
        /// 根据id获取
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<Materialgroupmodel> GetMaterialgroupById(long id)
        {
            return materialgroupServices.GetMaterialgroupById(id);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> UpdateMaterialgroup(Materialgroupmodel model)
        {
            return materialgroupServices.UpdateMaterialgroup(model);
        }
    }
}
